package com.example.leetdemo.finash;

public class Solution2734 {

    public static String smallestString(String s) {

        char[] charArr = s.toCharArray();
        int change = 0;
        for (int i = 0; i < charArr.length; i++) {
            if (i == charArr.length - 1 && String.valueOf(charArr).equals(s)) {
                charArr[i] = (char) (charArr[i] - 1);
                if (charArr[i] == '`') {
                    charArr[i] = 'z';
                }
                break;
            }
            if (charArr[i] == 'a' && change == 0) {
                continue;
            }
            if (charArr[i] == 'a' && change == 1) {
                break;
            }
            if (charArr[i] !='a') {
                change = 1;
                charArr[i] = (char) (charArr[i] - 1);
            }

        }

        return String.valueOf(charArr);
    }

    public static void main(String[] args) {
        String s = "aa";
        System.err.println(smallestString(s));
//        return
    }

}
